﻿
/*============== simpleIRC - http://matthias.van-eeghem.com/ ==============*
 *                                                                         *
 *  File: Nickalert.cs                                                          *
 *  Project: Nickalert                                                     *
 *  Author(s): Matthias Van Eeghem <matthias@van-eeghem.com>               *
 *                                                                         *
 * ========================================================================*
 *                                                                         *
 *  This program is free software: you can redistribute it and/or modify   *
 *  it under the terms of the GNU General Public License as published by   *
 *  the Free Software Foundation, either version 3 of the License, or      *
 *  (at your option) any later version.                                    *
 *                                                                         *
 *  This program is distributed in the hope that it will be useful,        *
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
 *  GNU General Public License for more details.                           *
 *                                                                         *
 *  You should have received a copy of the GNU General Public License      *
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.  *
 *                                                                         *
===========================================================================*/

using System.Windows.Media;

namespace simpleIRC.UI
{
    class Nickalert : AbstractClass
    {
        UserInterface UI = null;
        Colors Colors = null;

        /// <summary>
        /// Called when the Plugin gets loaded
        /// </summary>

        public override void OnPluginLoad()
        {
            UI = new UserInterface(MainWindow);
            Colors = new Colors(MainWindow);
        }

        /// <summary>
        /// Called when the plugin receives a message from the server
        /// </summary>
        /// <param name="channelName">The channel name</param>
        /// <param name="serverIndex">The server index</param>
        /// <param name="userName">The user that sent the message (empty string means the server sent something)</param>
        /// <param name="message">The message that was sent</param>

        public override void OnMessageSent(string channelName, int serverIndex, string userName, string message)
        {
            if (channelName != "" && userName != "")
            {
                // Get the nickname of the client on that server index.
                string Nickname = Core.ServerList[serverIndex].Nick;

                // Now check if the name is in the message, and make sure the user didn't say his or her own name.
                if (message.IndexOf(Nickname) != -1 && Nickname != userName)
                {
                    string CurrentChannel = (MainWindow.CurrentChannelWindow == -1) ? "" : Core.ChannelList[MainWindow.CurrentChannelWindow].Name.ToLower();

                    if (CurrentChannel != channelName.ToLower())
                    {
                        string Output = Colors.ApplyColor(Brushes.DarkGreen) + "[Highlight]" + Colors.ApplyColor(Brushes.Black) + " You have been nickalerted by " + userName + " on " + channelName + " saying: " + message + "\r";

                        UI.SendTextToCurrentWindow(Output);
                        Sounds.Play(Sounds.BASS_SOUND);
                    }
                }
            }
        }
    }
}
